<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>编辑测试用例信息 - 测试用例管理</title>
    <link href="/static/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="/static/css/bootstrap-icons.css">
    <style>
        body {
            background-color: #f0f7ff;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            padding-top: 20px;
        }
        .navbar {
            background-color: #0d6efd;
            margin-bottom: 30px;
        }
        .container {
            max-width: 900px;
        }
        .card {
            border: none;
            box-shadow: 0 4px 12px rgba(0,0,0,0.1);
        }
        .card-header {
            background-color: #0d6efd;
            color: white;
            font-weight: bold;
        }
        .form-group {
            margin-bottom: 15px;
        }
        .form-text {
            color: #6c757d;
            font-size: 0.875rem;
        }
        .form-section {
            margin-bottom: 25px;
            padding-bottom: 15px;
            border-bottom: 1px solid #e9ecef;
        }
        .form-section:last-child {
            border-bottom: none;
        }
        .btn-cancel {
            margin-left: 10px;
        }
        .required-mark {
            color: #dc3545;
        }
        .system-suggestions {
            position: absolute;
            z-index: 100;
            width: calc(100% - 1.5rem);
            max-height: 200px;
            overflow-y: auto;
            background-color: white;
            border: 1px solid #ced4da;
            border-radius: 0.25rem;
            display: none;
        }
        .system-suggestion-item {
            padding: 8px 12px;
            cursor: pointer;
        }
        .system-suggestion-item:hover {
            background-color: #e7f1ff;
        }
              /* 添加弹窗样式 */
        .alert-container {
            position: fixed;
            top: 20px;
            right: 20px;
            z-index: 1050;
            max-width: 350px;
        }
        .alert {
            padding: 15px;
            border-radius: 5px;
            margin-bottom: 10px;
            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
            display: flex;
            align-items: center;
            animation: slideIn 0.3s ease-out;
        }
        .alert-success {
            background-color: #d1e7dd;
            color: #0f5132;
            border: 1px solid #badbcc;
        }
        .alert-danger {
            background-color: #f8d7da;
            color: #842029;
            border: 1px solid #f5c2c7;
        }
        .alert i {
            margin-right: 10px;
            font-size: 1.2em;
        }
        .alert .close-btn {
            margin-left: auto;
            background: none;
            border: none;
            font-size: 1.2em;
            cursor: pointer;
            color: inherit;
        }
        @keyframes slideIn {
            from {
                transform: translateX(100%);
                opacity: 0;
            }
            to {
                transform: translateX(0);
                opacity: 1;
            }
        }
    </style>
</head>
<body>
    {% include 'common/header.html' %}

    <div class="container">
        <div class="card">
            <div class="card-header">
                <h4><i class="bi bi-pencil-square me-2"></i>编辑用例</h4>
            </div>
            <div class="card-body">
                {% if request.args.get('error') %}
                <div class="alert alert-danger">
                    {{ request.args.get('error') }}
                </div>
                {% endif %}

                <form method="POST" action="/update/{{ gateway_info.id }}">
                    <!-- 基本信息部分 -->
                    <div class="form-section">
                        <h5 class="text-primary mb-3"><i class="bi bi-card-checklist me-1"></i>基本信息</h5>

                        <div class="row">
                            <div class="col-md-6 form-group position-relative">
                                <label for="system_name" class="form-label">系统名称 <span class="required-mark">*</span></label>
                                <input type="text" class="form-control" id="system_name" name="system_name" required
                                       value="{{ gateway_info.system_name }}" placeholder="请输入系统名称">
                                <!-- 系统名称建议 -->
                                <div class="system-suggestions" id="systemSuggestions">
                                    {% for system in system_list %}
                                    <div class="system-suggestion-item" onclick="selectSystem('{{ system }}')">{{ system }}</div>
                                    {% endfor %}
                                </div>
                                <div class="form-text">{{ field_descriptions['system_name'] }}</div>
                            </div>

                            <div class="col-md-6 form-group">
                                <label for="case_id" class="form-label">用例编号 <span class="required-mark">*</span></label>
                                <input type="text" class="form-control" id="case_id" name="case_id" required
                                       value="{{ gateway_info.case_id }}" placeholder="请输入用例编号">
                                <div class="form-text">{{ field_descriptions['case_id'] }}</div>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-md-6 form-group">
                                <label for="module" class="form-label">模块 <span class="required-mark">*</span></label>
                                <input type="text" class="form-control" id="module" name="module" required
                                       value="{{ gateway_info.module }}" placeholder="请输入模块名称">
                                <div class="form-text">{{ field_descriptions['module'] }}</div>
                            </div>
                            <div class="col-md-6 form-group">
                                <label for="version" class="form-label">版本 <span class="required-mark">*</span></label>
                                <input type="text" class="form-control" id="version" name="version" required
                                       value="{{ gateway_info.version }}" placeholder="请输入版本号">
                                <div class="form-text">{{ field_descriptions['version'] }}</div>
                            </div>
                            <div class="col-md-6 form-group">
                                <label for="obj" class="form-label">对象</label>
                                <input type="text" class="form-control" id="obj" name="obj"
                                       value="{{ gateway_info.obj or '' }}" placeholder="请输入测试对象">
                                <div class="form-text">{{ field_descriptions['obj'] }}</div>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-md-6 form-group">
                                <label for="case_level" class="form-label">用例分级</label>
                                <input type="text" class="form-control" id="case_level" name="case_level"
                                       value="{{ gateway_info.case_level or '' }}" placeholder="请输入用例分级">
                                <div class="form-text">{{ field_descriptions['case_level'] }}</div>
                            </div>

                            <div class="col-md-6 form-group">
                                <label for="related_requirement_id" class="form-label">关联需求编号</label>
                                <input type="text" class="form-control" id="related_requirement_id" name="related_requirement_id"
                                       value="{{ gateway_info.related_requirement_id or '' }}" placeholder="请输入关联需求编号">
                                <div class="form-text">{{ field_descriptions['related_requirement_id'] }}</div>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-md-6 form-group">
                                <label for="change_point" class="form-label">变更点</label>
                                <input type="text" class="form-control" id="change_point" name="change_point"
                                       value="{{ gateway_info.change_point or '' }}" placeholder="请输入变更点">
                                <div class="form-text">{{ field_descriptions['change_point'] }}</div>
                            </div>

                            <div class="col-md-6 form-group">
                                <label for="operation_sequence" class="form-label">操作序列 <span class="required-mark">*</span></label>
                                <input type="number" class="form-control" id="operation_sequence" name="operation_sequence" required
                                       value="{{ gateway_info.operation_sequence }}" placeholder="请输入操作序列编号">
                                <div class="form-text">{{ field_descriptions['operation_sequence'] }}</div>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="title" class="form-label">标题 <span class="required-mark">*</span></label>
                            <input type="text" class="form-control" id="title" name="title" required
                                   value="{{ gateway_info.title }}" placeholder="请输入用例标题">
                            <div class="form-text">{{ field_descriptions['title'] }}</div>
                        </div>

                        <div class="form-group">
                            <label for="expected_result" class="form-label">预期结果 <span class="required-mark">*</span></label>
                            <textarea class="form-control" id="expected_result" name="expected_result" rows="3" required
                                      placeholder="请输入预期结果">{{ gateway_info.expected_result }}</textarea>
                            <div class="form-text">{{ field_descriptions['expected_result'] }}</div>
                        </div>
                    </div>

                    <!-- 执行结果部分 -->
                    <div class="form-section">
                        <h5 class="text-primary mb-3"><i class="bi bi-check-circle me-1"></i>执行结果</h5>

                        <div class="row">
                            <div class="col-md-6 form-group">
                                <label for="execution_result" class="form-label">执行结果</label>
                                <textarea class="form-control" id="execution_result" name="execution_result" rows="2"
                                          placeholder="请输入执行结果">{{ gateway_info.execution_result or '' }}</textarea>
                                <div class="form-text">{{ field_descriptions['execution_result'] }}</div>
                            </div>

                            <div class="col-md-6 form-group">
                                <label for="bug_id" class="form-label">bug编号</label>
                                <input type="text" class="form-control" id="bug_id" name="bug_id"
                                       value="{{ gateway_info.bug_id or '' }}" placeholder="请输入bug编号">
                                <div class="form-text">{{ field_descriptions['bug_id'] }}</div>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-md-6 form-group">
                                <label for="execution_version" class="form-label">执行版本</label>
                                <input type="text" class="form-control" id="execution_version" name="execution_version"
                                       value="{{ gateway_info.execution_version or '' }}" placeholder="请输入执行版本">
                                <div class="form-text">{{ field_descriptions['execution_version'] }}</div>
                            </div>

                            <div class="col-md-6 form-group">
                                <label for="notes" class="form-label">备考</label>
                                <input type="text" class="form-control" id="notes" name="notes"
                                       value="{{ gateway_info.notes or '' }}" placeholder="请输入备注信息">
                                <div class="form-text">{{ field_descriptions['notes'] }}</div>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-md-6 form-group">
                                <label for="implementer" class="form-label">实施者</label>
                                <input type="text" class="form-control" id="implementer" name="implementer"
                                       value="{{ gateway_info.implementer or '' }}" placeholder="请输入实施者">
                                <div class="form-text">{{ field_descriptions['implementer'] }}</div>
                            </div>

                            <div class="col-md-6 form-group">
                                <label for="implementation_date" class="form-label">实施日</label>
                                <input type="text" class="form-control" id="implementation_date" name="implementation_date"
                                       value="{{ gateway_info.implementation_date or '' }}" placeholder="请输入实施日期">
                                <div class="form-text">{{ field_descriptions['implementation_date'] }}</div>
                            </div>
                        </div>
                    </div>

                    <!-- 自动化相关部分 -->
                    <div class="form-section">
                        <h5 class="text-primary mb-3"><i class="bi bi-robot me-1"></i>自动化相关</h5>

                        <div class="row">
                            <div class="col-md-6 form-group">
                                <label for="is_smoke" class="form-label">是否冒烟</label>
                                <select class="form-select" id="is_smoke" name="is_smoke">
                                    <option value="">请选择</option>
                                    <option value="是" {% if gateway_info.is_smoke =='是' %}selected{% endif %}>是</option>
                                    <option value="否" {% if gateway_info.is_smoke =='否' %}selected{% endif %}>否</option>
                                </select>
                                <div class="form-text">{{ field_descriptions['is_smoke'] }}</div>
                            </div>

                            <div class="col-md-6 form-group">
                                <label for="is_automated" class="form-label">是否自动化 <span class="required-mark">*</span></label>
                                <select class="form-select" id="is_automated" name="is_automated" required>
                                    <option value="">请选择</option>
                                    <option value="是" {% if gateway_info.is_automated =='是' %}selected{% endif %}>是</option>
                                    <option value="否" {% if gateway_info.is_automated =='否' %}selected{% endif %}>否</option>
                                </select>
                                <div class="form-text">{{ field_descriptions['is_automated'] }}</div>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="automation_status" class="form-label">自动化状态 <span class="required-mark">*</span></label>
                            <select class="form-select" id="automation_status" name="automation_status" required>
                                <option value="">请选择</option>
                                <option value="未实现" {% if gateway_info.automation_status =='未实现' %}selected{% endif %}>未实现</option>
                                <option value="已实现" {% if gateway_info.automation_status =='已实现' %}selected{% endif %}>已实现</option>
                                <option value="维护中" {% if gateway_info.automation_status =='维护中' %}selected{% endif %}>维护中</option>
                                <option value="已废弃" {% if gateway_info.automation_status =='已废弃' %}selected{% endif %}>已废弃</option>
                                <option value="已废弃" {% if gateway_info.automation_status =='受阻' %}selected{% endif %}>已废弃</option>
                            </select>
                            <div class="form-text">{{ field_descriptions['automation_status'] }}</div>
                        </div>

                        <div class="form-group">
                            <label for="pre_operation" class="form-label">前置操作</label>
                            <textarea class="form-control" id="pre_operation" name="pre_operation" rows="2"
                                      placeholder="请输入前置操作步骤">{{ gateway_info.pre_operation or '' }}</textarea>
                            <div class="form-text">{{ field_descriptions['pre_operation'] }}</div>
                        </div>

                        <div class="form-group">
                            <label for="post_operation" class="form-label">后置操作</label>
                            <textarea class="form-control" id="post_operation" name="post_operation" rows="2"
                                      placeholder="请输入后置操作步骤">{{ gateway_info.post_operation or '' }}</textarea>
                            <div class="form-text">{{ field_descriptions['post_operation'] }}</div>
                        </div>
                    </div>

                    <!-- 数据库与接口部分 -->
                    <div class="form-section">
                        <h5 class="text-primary mb-3"><i class="bi bi-database me-1"></i>数据库与接口</h5>

                        <div class="form-group">
                            <label for="db_verification" class="form-label">数据库校验</label>
                            <textarea class="form-control" id="db_verification" name="db_verification" rows="2"
                                      placeholder="请输入数据库校验内容">{{ gateway_info.db_verification or '' }}</textarea>
                            <div class="form-text">{{ field_descriptions['db_verification'] }}</div>
                        </div>

                        <div class="form-group">
                            <label for="db_result" class="form-label">数据库结果</label>
                            <textarea class="form-control" id="db_result" name="db_result" rows="2"
                                      placeholder="请输入数据库校验结果">{{ gateway_info.db_result or '' }}</textarea>
                            <div class="form-text">{{ field_descriptions['db_result'] }}</div>
                        </div>

                        <div class="row">
                            <div class="col-md-6 form-group">
                                <label for="url" class="form-label">URL</label>
                                <input type="text" class="form-control" id="url" name="url"
                                       value="{{ gateway_info.url or '' }}" placeholder="请输入接口URL">
                                <div class="form-text">{{ field_descriptions['url'] }}</div>
                            </div>

                            <div class="col-md-6 form-group">
                                <label for="request_type" class="form-label">请求类型</label>
                                <select class="form-select" id="request_type" name="request_type">
                                    <option value="">请选择</option>
                                    <option value="GET" {% if gateway_info.request_type =='GET' %}selected{% endif %}>GET</option>
                                    <option value="POST" {% if gateway_info.request_type =='POST' %}selected{% endif %}>POST</option>
                                    <option value="PUT" {% if gateway_info.request_type =='PUT' %}selected{% endif %}>PUT</option>
                                    <option value="DELETE" {% if gateway_info.request_type =='DELETE' %}selected{% endif %}>DELETE</option>
                                    <option value="PATCH" {% if gateway_info.request_type =='PATCH' %}selected{% endif %}>PATCH</option>
                                </select>
                                <div class="form-text">{{ field_descriptions['request_type'] }}</div>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="request_params" class="form-label">请求参数</label>
                            <textarea class="form-control" id="request_params" name="request_params" rows="2"
                                      placeholder="请输入请求参数">{{ gateway_info.request_params or '' }}</textarea>
                            <div class="form-text">{{ field_descriptions['request_params'] }}</div>
                        </div>

                        <div class="row">
                            <div class="col-md-6 form-group">
                                <label for="api_code" class="form-label">api_code</label>
                                <input type="text" class="form-control" id="api_code" name="api_code"
                                       value="{{ gateway_info.api_code or '' }}" placeholder="请输入接口返回码">
                                <div class="form-text">{{ field_descriptions['api_code'] }}</div>
                            </div>

                            <div class="col-md-6 form-group">
                                <label for="api_msg" class="form-label">api_msg</label>
                                <input type="text" class="form-control" id="api_msg" name="api_msg"
                                       value="{{ gateway_info.api_msg or '' }}" placeholder="请输入接口返回消息">
                                <div class="form-text">{{ field_descriptions['api_msg'] }}</div>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="source_sheet" class="form-label">来源工作表</label>
                            <input type="text" class="form-control" id="source_sheet" name="source_sheet"
                                   value="{{ gateway_info.source_sheet or '' }}" placeholder="请输入来源工作表名称" readonly>
                            <div class="form-text">{{ field_descriptions['source_sheet'] }}（此信息由系统自动生成，不可修改）</div>
                        </div>
                    </div>

                    <!-- 按钮区域 -->
                    <div class="d-flex justify-content-end">
                        <button type="submit" class="btn btn-primary">
                            <i class="bi bi-save me-1"></i>保存修改
                        </button>
                        <button type="button" class="btn btn-secondary btn-cancel" onclick="window.history.back()">
                            <i class="bi bi-x-circle me-1"></i>取消
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    {% include 'common/field_modal.html' %}

    {% include 'common/alert.html' %}

    <script src="/static/js/bootstrap.bundle.min.js"></script>
    <script src="/static/js/system_suggest.js"></script>
    <script src="/static/js/util.js"></script>
    <script>
                // 页面特有JS逻辑
        document.addEventListener('DOMContentLoaded', function() {
            // 复制提示逻辑
            {% if request.args.get('copy') == '1' %}
                showAlert('用例复制成功，请修改必要信息', 'success');
            {% endif %}
        });
    </script>
</body>
</html>
